#include "DecoyHeadWestState.h"
#include "AttractiveField.h"
#include "SniperAssasinateTanksState.h"
#include "PDController.h"
#include "CaptureFlagState.h"
#include "DecoyHeadEastState.h"

DecoyHeadWestState::DecoyHeadWestState(void)
{
	target = new AttractiveField(Vector2(250, -100));
}


DecoyHeadWestState::~DecoyHeadWestState(void)
{
	delete target;
}

Command DecoyHeadWestState::GetCommand(MultiAgent* agent) {
	if (SniperAssasinateTanksState::TargetsEliminated()) {
		agent->setState(new CaptureFlagState());
		return agent->GetCommand();
	}

	Vector2 tank_pos(agent->getTank()->pos[0], agent->getTank()->pos[1]);
	Vector2 trajectory = target->get_trajectory(tank_pos);

	// If we have gone far enough south, head back north
	if (trajectory.magnitude() < 50) {
		agent->setState(new DecoyHeadEastState());
		return agent->GetCommand();
	}

	Command cmd = PDController::instance()->GetComand(agent->getTank(), trajectory);
	cmd.speed(1.0);
	return cmd;

}
